package internationalenergytradingplatform.controller.AdministratorsController;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import internationalenergytradingplatform.VO.OrderPageQueryVO;
import internationalenergytradingplatform.context.BaseContext;
import internationalenergytradingplatform.dao.OrderMapper;
import internationalenergytradingplatform.dto.OrderPageQueryDTO;
import internationalenergytradingplatform.result.PageResult;
import internationalenergytradingplatform.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/administrator-order")
public class AdministratorOrderController {

    @Autowired
    OrderMapper orderMapper;
    /**
     * 管理员分页查询
     */
    @GetMapping("/paginationQuery")
    public Result<PageResult> adminPagingToQueryAllOrder(OrderPageQueryDTO orderPageQueryDTO){

        PageHelper.startPage(orderPageQueryDTO.getPage(), orderPageQueryDTO.getPageSize());
        Page<OrderPageQueryVO> page = orderMapper.orderPageQueryAdmin(orderPageQueryDTO);
        long total = page.getTotal();
        List<OrderPageQueryVO> records = page.getResult();
        log.info("管理员分页查询结果：{}", records);
        PageResult pageResult = new PageResult(total, records);
        return Result.success(pageResult);
    }




}
